package cn.xfdzx.android.apps.shop.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.HomeMarketInitDataBeen;
import cn.xfdzx.android.apps.shop.contract.ItemClickListener;

/**
 * @author gzk
 * @date 2020/4/13 0013
 * description：新发地市场价格实时指南
 */
public class XfdTimeZhiNanAdapter extends RecyclerView.Adapter<XfdTimeZhiNanAdapter.MyViewHolder> {

    private ItemClickListener mItemClickListener;
    private List<HomeMarketInitDataBeen.XfdPriceArrayBean> list=new ArrayList<>();
    private Context context;


    public XfdTimeZhiNanAdapter(Context context) {

        this.context = context;
    }

    public void setData( List<HomeMarketInitDataBeen.XfdPriceArrayBean> list){
        this.list = list;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_xfd_price_tiem_zhinan, parent, false);

        MyViewHolder myHolder = new MyViewHolder(inflate);
        int parentHeight= parent.getHeight();
        parent.getWidth();
        ViewGroup.LayoutParams layoutParams = myHolder.itemView.getLayoutParams();
        layoutParams.height =  (parentHeight/ 5);
        return myHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull final MyViewHolder holder, final int position) {

        if (!list.isEmpty()) {
            holder.setData(list.get(position%list.size()));
        }
//        holder.itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                mItemClickListener.onItemClick(position);
//            }
//        });
    }


    @Override
    public int getItemCount() {
        return Integer.MAX_VALUE;
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_xfd_name)
        TextView tvXfdName;
        @BindView(R.id.tv_xfd_di_price)
        TextView tvXfdPrice;
        @BindView(R.id.tv_xfd_average_price)
        TextView tvXfdAveragePrice;
        @BindView(R.id.tv_xfd_gao_price)
        TextView tvXfdGaoPrice;
        @BindView(R.id.tv_xfd_specifications)
        TextView tvXfdSpecifications;
        @BindView(R.id.tv_xfd_unit)
        TextView tvXfdUnit;
        @BindView(R.id.tv_xfd_release_time)
        TextView tvXfdReleaseTime;

        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);

        }
        void setData(HomeMarketInitDataBeen.XfdPriceArrayBean bean){
            tvXfdName.setText(bean.getName()+"");
            tvXfdPrice.setText(bean.getBottom_price()+"");
            tvXfdAveragePrice.setText(bean.getAverage_price()+"");
            tvXfdGaoPrice.setText(bean.getTop_price()+"");
            tvXfdSpecifications.setText(bean.getSpecifications()+"");
            tvXfdUnit.setText(bean.getCompany()+"");
            tvXfdReleaseTime.setText(bean.getRelease_date()+"");
        }

    }


    public void setOnItemClickListener(ItemClickListener itemClickListener) {
        this.mItemClickListener = itemClickListener;

    }

}
